﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using Wicresoft.EKA.Atrium.WCFWS.CMDBInstanceManager;

namespace Wicresoft.EKA.Atrium.WCFWS
{
    public class CMDBInstanceMgr
    {
        public GetInstancesOutput ListInstances()
        {

            System.Net.ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificatePolicy.CheckValidationResult;
            CMDBInstanceManager.AtriumInstances_PortTypeClient client = new CMDBInstanceManager.AtriumInstances_PortTypeClient();

            BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
            elements.Find<SecurityBindingElement>().IncludeTimestamp = false;
            client.Endpoint.Binding = new CustomBinding(elements);

            client.ClientCredentials.UserName.UserName = "Demo";
            client.ClientCredentials.UserName.Password = "Pass01!";

            // var r = client.GetUIComponents(new GetUIComponents());

            //var re = client.CreateInstance(new CreateInstance()
            //{
            //    datasetId=""
            //});

            //var re = client.DeleteInstance(new DeleteInstance()
            //    {
            //        datasetId = "BMC.ASSET",
            //        deleteOption = InstanceDeleteOption.DERIVED_INSTANCE_FOUND,
            //        instanceInfo = new DeleteInstanceInfoIn()
            //        {
            //            classNameId = new ClassNameId()
            //            {
            //                className = "BMC_Application",
            //                namespaceName = "BMC.CORE"
            //            },
            //            instanceId = "OI-DA97C8F9A6D64984B1990EB8831A89A0"
            //        }
            //        //extensions = new ExtensionList()
            //        //{
            //        //    Any=
            //        //}
            //    });

            //client.g

            //必填字段 。。问题 
            return client.GetInstances(new GetInstances()
                 {
                     //loginInfo = new CMDBInstanceManager.LoginInfo()
                     //{
                     //    authentication = "Pass01!",
                     //    locale = "",
                     //    timeZone = ""
                     //},
                     classNameId = new ClassNameId()
                     {
                         className = "BMC_Application",
                         namespaceName = "BMC.CORE"
                     },
                     firstRetrieve = 10,
                     datasetId = "BMC.ASSET",
                     query = "1=1",
                     //attributes = new string[] { "Item", "Type" },
                     sortOrder = new SortOrder[] { 
                     new SortOrder()
                     {
                         attributeName="Item",
                         sortOrder=SortOrderType.ASCENDING
}
                     },
                     getMask = GetMask.GET_MASK_NONE
                 });

        }
    }
}
